package com.dk.service.serviceImpl;

import com.dk.mapper.OrderRecordMapper;
import com.dk.pojo.OrderRecord;
import com.dk.service.OrderRecordService;
import com.dk.vo.OrderRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderRecordServiceImpl implements OrderRecordService {

    @Autowired
    OrderRecordMapper orderRecordMapper;

    public List<OrderRecord> getAllOrderRecord(){
        return orderRecordMapper.getAllOrderRecord();
    }

    public List<OrderRecordVo> getOrderRecordsByUid(String uid){
        return parseVo(orderRecordMapper.getOrderRecordByUid(uid));
    }

    private List<OrderRecordVo> parseVo(List<OrderRecord> list){
        List<OrderRecordVo> orderRecordVoList=new ArrayList<>();
        for(OrderRecord orderRecord:list){
            OrderRecordVo orderRecordVo=new OrderRecordVo();
            orderRecordVo.setOid(orderRecord.getOid());
            String time=orderRecord.getFinishTime().toString();
            orderRecordVo.setTime(time.substring(0,time.lastIndexOf(":")));
            orderRecordVoList.add(orderRecordVo);
        }
        return orderRecordVoList;
    }
}
